import { shallowEqual, useDispatch, useSelector } from "react-redux";
import { selectLocale, setLocale } from "@/store/reducer/layoutSlice";
import zhCN from "antd/es/locale/zh_CN";
import enUS from "antd/es/locale/en_US";
import idID from "antd/es/locale/id_ID";
import local_zhCN from "@/locales/zh-CN";
import local_enUS from "@/locales/en-US";
import local_idID from "@/locales/id-ID";

const message: { [key: string]: any } = {
  "zh-CN": { ...zhCN, ...local_zhCN },
  "en-US": { ...enUS, ...local_enUS },
  "id-ID": { ...idID, ...local_idID },
};

export const useLocale = () => {
  const dispatch = useDispatch();
  const locale = useSelector(selectLocale, shallowEqual);
  return {
    locale: locale,
    message: message[locale],
    setLang: (lang: string) => dispatch(setLocale({ locale: lang })),
  };
};

export default useLocale;
